<?php

/**
 * @author [TinyBear]
 * @copyright 2011
 * @action 
 */


require_once('toauth/qq.oauth.php');
$session=new CHttpSession;
print_r($session);exit;
//Callback
$oURI = explode("authorization",$_SERVER['PHP_SELF']);
$config['oauth_callback'] = "http://".$_SERVER ['HTTP_HOST'].$oURI[0]."authorization.php";

$config['oauth_consumer_key'] = 'bae2a825d06a4e42855ab1aac7c2c120';
$config['oauth_consumer_secret'] = 'bbfc783d446e68b9e02c3c972cfcd0c8';

$_SESSION["appk"] = $config['oauth_consumer_key'];
$_SESSION["appks"] = $config['oauth_consumer_secret'];

$oOAuth = new TOAuth($_SESSION["appk"], $_SESSION["appks"]);

if(isset($_GET["oauth_token"])&&$_GET["oauth_verifier"]) {//授权第二步
	
	$aParam = array(
			"oauth_token" => $_GET["oauth_token"],
			"oauth_verifier" => $_GET["oauth_verifier"],
	);
	
	$oOAuth->setToken($aParam["oauth_token"],$_SESSION["oauth_token_secret"]);
	$sURL =  TOAuth::$oauth_access_token;
	$sReturn = $oOAuth->send($aParam, $sURL);
	parse_str($sReturn, $aReturn);
} else {

	$aParam = array(
		"oauth_callback" => $config['oauth_callback'],
	);
	$sURL = TOAuth::$oauth_request_token;
	$sReturn = $oOAuth->send($aParam, $sURL);
	parse_str($sReturn, $aReturn);
	$_SESSION["oauth_token_secret"] = $aReturn["oauth_token_secret"];
	$sRedirect =  TOAuth::$oauth_authorize."?oauth_token=".$aReturn["oauth_token"];
	header("Location:".$sRedirect); 

}

?>